home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
Mac Stdg 4.4 Folder
/
Samples
/
hello.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-09
|
2KB
|
62 lines
/*
* Hello Stdg World by Loki
*
* An example program which shows how easy it is to program with Stdg.
* The example creates a window and draws a string on to it.
* There are 8 library functions and 7 variables used.
*/
#include "stdg.h"
/*
* The redraw function is called when a window needs redrawing.
* It should redraw the entire window.
*/
void redraw(window *w)
{
/*
* First, we calculate some heights and widths so
* we know where to place our message on the window.
* The point we find is the top-left point of the string.
*/
char *hello_string = "Hello, World!";
long str_width = strwidth(sys_font, hello_string);
long str_height = sys_font->height;
long win_width = dx(w->r); /* delta-x i.e. width */
long win_height = dy(w->r); /* delta-y i.e. height */
point p = pt((win_width-str_width)/2, (win_height-str_height)/2);
/*
* Now we actually draw the string on the window's bitmap w->b
* at point p using the system font and grey text.
*/
draw_string(w->b, p, sys_font, hello_string, GREY);
}
/*
* The main function is where the program begins.
*/
int main(int argc, char **argv)
{
window *w;
/* Initilise the graphical interface. */
ginit("Hello Stdg World", NULL, NULL);
/* Create a new window which is the size of the screen. */
w = new_window("Hello Window", rect(0,0,0,0), Titlebar|Maximize|Resize);
/* Link our redraw function to this new window. */
set_winfns(w, NULL, NULL, &redraw);
/* Display the window on the screen. */
show_window(w);
/* Now poll for events but do nothing with them. */
while(1)
can_event();
return 0;
}